package Model.Wall;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class PostTime {
	Calendar calendar = new GregorianCalendar();
	public static int MILSEC_IN_SECS = 1000;
	public static int SEC_IN_MIN = 60;
	public static int SEC_IN_HR = 3600;
	public static int SEC_IN_DAY=86400;
	public static int SEC_IN_WEEK=604800;
	public static int SEC_IN_MONTH=2419200;
	public static int SEC_IN_YEAR=29030400;
	
	
	public int getCurrentTime(){
		return (int) (calendar.getTimeInMillis() / MILSEC_IN_SECS);
	}
	public String postTimeMessage(int posttime){
		
		
		String message = "0 seconds ago";
		
		int currentTime = (int) (calendar.getTimeInMillis() / MILSEC_IN_SECS);
		
		int time_difference =  currentTime - posttime ; 
		int seconds = time_difference ; 
		int minutes = time_difference / SEC_IN_MIN ;
		int hours = time_difference / SEC_IN_HR ; 
		int days = time_difference / SEC_IN_DAY ; 
		int weeks = time_difference / SEC_IN_WEEK ; 
		int months = time_difference / SEC_IN_MONTH ; 
		int years = time_difference / SEC_IN_YEAR ; 
		if(seconds<0){
			message="A long time ago!";
		}
		else if(seconds <= 60)
		{
		message=seconds+" seconds ago"; 
		}
		else if(minutes <=60)
		{
		   if(minutes==1)
		   {
		     message=" one minute ago"; 
		    }
		   else
		   {
		   message=minutes + " minutes ago"; 
		   }
		}
		else if(hours <=24)
		{
		   if(hours==1)
		   {
		   message=" one hour ago";
		   }
		  else
		  {
		  message=hours+" hours ago";
		  }
		}
		else if(days <=7)
		{
		  if(days==1)
		   {
		   message=" one day ago";
		   }
		  else
		  {
		  message=days+" days ago";
		  }


		  
		}
		else if(weeks <=4)
		{
		  if(weeks==1)
		   {
		   message=" one week ago";
		   }
		  else
		  {
		  message=weeks+" weeks ago";
		  }
		 }
		else if(months <=12)
		{
		   if(months==1)
		   {
		   message=" one month ago";
		   }
		  else
		  {
		  message=months+" months ago";
		  }
		 
		   
		}

		else
		{
		if(years==1)
		   {
		   message=" one year ago";
		   }
		  else
		  {
		  message=years+" years ago";
		  }


		}



		return message;
	}
}

